package com.lzx.activity.controller;

import com.lzx.activity.entity.Activity;
import com.lzx.activity.entity.vo.ActivityOSSParams;
import com.lzx.activity.entity.vo.ActivityParams;
import com.lzx.activity.service.ActivityService;
import com.lzx.common.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lzx
 * @since 2022-10-31
 */
@RestController
@RequestMapping("/activity/activity")
public class ActivityController {
    @Resource
    private ActivityService activityService;

    //根据id获取活动图片并修改图片
    @PutMapping("/getImageAndUpdateImage")
    public String getImageAndUpdateImage(@RequestBody ActivityOSSParams activityOSSParams){
        return activityService.getImageAndUpdateImage(activityOSSParams);
    }

    //获取活动列表
    @GetMapping("/getActivityList/{current}/{size}")
    public R getActivityList(@PathVariable int current, @PathVariable int size){
        return activityService.getActivityList(current, size);
    }

    //新增活动
    @PostMapping("/addActivity")
    public R addActivity(@RequestBody Activity activity) {
        return activityService.addActivity(activity);
    }

    //修改活动
    @PutMapping("/updateActivity")
    public R updateActivity(@RequestBody Activity activity) {
        return activityService.updateActivity(activity);
    }

    //删除活动
    @DeleteMapping("/deleteActivity/{ids}")
    public R deleteActivity(@PathVariable List<Long> ids) {
        return activityService.deleteActivity(ids);
    }

    //根据id获取活动信息
    @GetMapping("/{id}")
    public R getActivity(@PathVariable Long id) {
        return activityService.getActivity(id);
    }

    //搜索
    @PostMapping("/searchActivity")
    public R searchActivity(@RequestBody ActivityParams activityParams) {
        return activityService.searchActivity(activityParams);
    }

    //导出
    @GetMapping("/exportActivity")
    public void exportActivity(HttpServletResponse response) {
        activityService.exportActivity(response);
    }
}
